// 生成默认时间,默认是半年
export const defaultTime = () => {
  const end = new Date()
  const start = new Date()
  start.setMonth(start.getMonth() - 6)
  const startTime = Math.floor(start.getTime() / 1000)
  const endTime = Math.floor(end.getTime() / 1000)

  return [startTime, endTime]
}

// 计算正确率对应颜色
export const getColorByRate = rate => {
  if (rate >= 0.95) {
    return '#6FA976'
  } else if (rate >= 0.85) {
    return '#4EC680'
  } else if (rate >= 0.75) {
    return '#71D764'
  } else if (rate >= 0.6) {
    return '#FF6D65'
  } else if (rate >= 0) {
    return '#D46262'
  } else {
    return '#E0E0E0'
  }
}
// 根据id查找节点
export const findNodeById = (node, id) => {
  if (node.id === id) {
    return JSON.parse(JSON.stringify(node))
  }

  if (node.children && node.children.length > 0) {
    for (let child of node.children) {
      let found = findNodeById(child, id)
      if (found) {
        return JSON.parse(JSON.stringify(found))
      }
    }
  }

  return null
}
